<#assign ctx = request.contextPath />
<!--<!DOCTYPE html-->
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1 ,minimum-scale=1.0 ,maximum-scale=1.0" user-scalable=no>
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>登录页面</title>
    <link href="${ctx}/assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/assets/css/weixing.css" rel="stylesheet" />
    <link rel="stylesheet" href="${ctx}/assets/css/sco.message.css" />
    <link rel="stylesheet" href="${ctx}/assets/css/weixing.css" />
    <style>
    	body{
    		background-image:url(${ctx}/assets/img/0-bj.jpg);
    		background-repeat: no-repeat;
    		background-size: 100% 100%;
    	}
    </style>
  </head>
  <body>
	<form id="weixin_form"  action="${ctx}/wx/v1/orderData" method="post">
	  	<input type="hidden" id="wxuser" name="wxuser" value="${openId?if_exists}">
		<div class="well">
			<h3 id="text"></h3>
			<div class="input-group">
				<input id="telephone" type="text" class="form-control" placeholder="输入手机号码" placeholder=".input-lg">
				<span class="input-group-btn">
				    <button id="yzNumber" class="btn btn-default" type="button">获取验证码</button>
				</span>
			</div><!-- /input-group -->
			<div class="form-group">
				<input id="vcode" class="form-control floating-label" id="focusedInput" type="text" placeholder="请输入验证码" placeholder=".input-lg" >
			</div>
				 <button type="button" class="btn btn-default btn-block" id="submit_form">登录</button>
		</div>
	</form>		  
    <script src="${ctx}/assets/js/jquery-1.11.0.min.js"></script>
	<script src="${ctx}/assets/js/bootstrap.min.js"></script>
	<script src="${ctx}/assets/js/jquery.autocomplete.min.js"></script>
	<script type="text/javascript">
	window.daijia = {ctx:'${ctx}'};
	</script>
	<script src="${ctx}/assets/js/wxcommon.js"></script>
	<script src="${ctx}/assets/js/sco.message.js"></script>
    <script type="text/javascript">
    
    	if(em.is_weixin()){
    	
    		<#if hasReturnUrl>
				var base_url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=${setting.wxAppId?if_exists}&redirect_uri="+URLEncode('${setting.wxServer?if_exists}wx/v1/bind?returnUrl='+URLEncode('${returnUrl}')+'')+"&response_type=code&scope=snsapi_base&state=null#wechat_redirect";
			<#else>
				var base_url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=${setting.wxAppId?if_exists}&redirect_uri="+URLEncode('${setting.wxServer?if_exists}wx/v1/bind')+"&response_type=code&scope=snsapi_base&state=null#wechat_redirect";
			</#if>	
			
		
			var _obj = em.UrlGet();
			
			if(_obj.code){
				$.post('${ctx}/wx/v1/userInfo',{'code':_obj.code},function(data){
					if(data.object){
						$("#wxuser").val(data.object.openId);
						$("#telephone").val(data.object.phone);
					}
				},'json');
			}
			else{
				window.location.replace(base_url);
			}
		}
		
		$(document).ready(function(){
		
			$("#yzNumber").bind('click',function(){
				var phone=$("#telephone").val();
				var regex = /^1\d{10}$/;
				if(regex.test(phone) && phone.length==11){
					$.get('${ctx}/wx/v1/sendVcode',{'phone':phone},function(data){
					
						if(data.success){
						$.scojs_message("验证码已发送成功", $.scojs_message.TYPE_OK);
						calculagraph(0);
						}
						else{
							if(data.errorcode=="0"){
								calculagraph(data.object);
							}
							else if(data.errorcode=="1"){
								$.scojs_message("短信发送失败，请稍后再试", $.scojs_message.TYPE_ERROR);
							}
						}
					});	
				}
				else{
						$.scojs_message("号码输入错误，请重新输入！", $.scojs_message.TYPE_ERROR);
				}
			});
			//表单提交
			$("#submit_form").click(function(){
				$('#loadblacklayer').show();
				
				var phone = $("#telephone").val();
				if (phone == "" || phone.length != 11){
						$.scojs_message("请正确填写电话号码！", $.scojs_message.TYPE_ERROR);
						return;
				}
					
				if(($("#vcode").val()).length==0 || $("#vcode").val().length!=4){
						$.scojs_message("请正确输入验证码！", $.scojs_message.TYPE_ERROR);
						return;
				}
					
				var params = {telephone:phone,wxuser:$("#wxuser").val(),vcode:$("#vcode").val()};
					
				$.post('${ctx}/wx/v1/bundlingInfo',params,function(data){
					$('#loadblacklayer').show();
					if(data.errorcode=='outTime'){
						$('#loadblacklayer').hide();
						$.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
						
					}
					else if(data.errorcode=='error'){
						$('#loadblacklayer').hide();
						$.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
					}
					else if(data.errorcode=='help'){
						$('#loadblacklayer').hide();
						$.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
					}else{	
						if(data.success){
							<#if hasReturnUrl>
								window.location.href='${returnUrl}';
							<#else>
								window.location.href='${ctx}/wx/v1/profile?phone='+data.object;
							</#if>	
						}
						else{
							$('#loadblacklayer').hide();
							$.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
						}
					}	
				});
				
			});
		})
	</script>
  </body>
</html>
